<template>
	<view class="choose-position">
		<view class="title">选择您沟通的岗位</view>
		<view class="list-block">
			<view @click="selected=item.id" :class="selected==item.id?'active':''" class="list-item" v-for="(item,index) in list" :key="item.id">
				<view class="list-info">
					<view class="title">{{item.jobTitle}}</view>
					<view class="address">{{item.jobAddress}}</view>
					<view class="label-block">
						<view class="label-item" v-for="label in item.welfareList">{{label}}</view>
					</view>
					<view class="wage" v-if="item.minSalary">{{item.minSalary}}-{{item.maxSalary}}<text class="unit">元</text></view>
					<view class="wage" v-else>面议</view>
				</view>
			</view>
		</view>
		<view class="btn-block">
			<view class="confirm-btn" @click="handleSave">确定</view>
		</view>
	</view>
</template>

<script>
	import {getMyPublish} from '@/api/position.js'
	import {
		getUser
	} from '@/api/user.js'
	export default{
		data(){
			return{
				list:[],
				selected:null,
			}
		},
		methods:{
			getList(){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				getMyPublish({recruitState:3,page:1,limit:100}).then((res)=>{
					this.list=res.list;
					if(this.list.length<=0){
							this.showToast('请先发布岗位', () => {
								uni.navigateBack()
							});
						
					}
				})
			},
			handleSave(){
				if(!this.selected){
					this.showToast('请先选择岗位');
					return;
				}
				uni.$emit('chooseChatPosition',this.selected)
				uni.navigateBack()
			}
		},
		onShow() {
			getUser({
				type: 2
			}).then((res) => {
				const com = res;
				if (com.authenticationStatus == 3) {
					this.showToast('等待审核中，暂不可操作', () => {
						this.$store.dispatch('user/getUser')
						uni.navigateBack()
					});
				} else if (com.authenticationStatus == 4) {
					this.showToast('审核不通过，请重新上传', () => {
						this.$store.dispatch('user/getUser')
						uni.navigateBack()
					});
					
				}
			})
			
		},
		onLoad() {
			this.getList();
		}
	}
</script>

<style lang="scss" scoped>
	.choose-position{
		padding: 30rpx;
		.btn-block{
			position: fixed;
			bottom: 0;
			left: 0;
			height: 120rpx;
			background: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			.confirm-btn{
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #fe7526;
				border-radius: 60rpx;
				width:340rpx;
				color: #fff;
			}
		}
		
		.title{
			font-size: 40rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}
		.list-block{
			width: 100%;
			padding-bottom: 120rpx;
			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				box-shadow: 0 0 10px 0 #efefef;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				margin-bottom: 20rpx;
				border: 1px solid rgba(0, 0, 0, 0);
				.list-info {
					width: calc(100% - 0rpx);
					display: flex;
					flex-direction: column;
			
					view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
			
					.title {
						color: #000;
						font-weight: bold;
						font-size: 34rpx;
					}
			
					.address {
						color: #999;
						font-size: 26rpx;
						margin-top: 20rpx;
					}
			
					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;
			
						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}
			
					.wage {
						color: #FE7526;
						font-size: 36rpx;
						font-weight: bold;
			
						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}
			.list-item.active{
				border: 1px solid #fe7526;
			}
		}
	}
</style>